package business;

import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

import javax.xml.bind.ValidationException;

import controller.ISistema;

public class BusinessDelegate {

	private static BusinessDelegate instance = null;
	private ISistema sistema;

	private BusinessDelegate() {

	}

	public static BusinessDelegate getInstance() {
		if (instance == null)
			return new BusinessDelegate();
		else
			return instance;
	}

	public ISistema getSistema() throws ValidationException {

		try {

			//System.setSecurityManager(new RMISecurityManager());
			Registry registry = LocateRegistry.getRegistry("localhost");
			sistema = (ISistema) registry.lookup("Sistema");
		} catch (NotBoundException e) {
			e.printStackTrace();
			throw new ValidationException("Error de conexion con el servidor");

		} catch (RemoteException e) {
			e.printStackTrace();
			throw new ValidationException("Error de conexion con el servidor");
		}
		return sistema;
	}

}
